#include "IniColorizer.h"
#include <windows.h>


IniColorizer::IniColorizer()
{
	text::ColorEntry entry = win7::Win7GetTextBoxTextColor();
	colors.Resize(5);

	//text color
	colors[NORMAL_COLOR] = entry;

	//section color
	entry.normal.text = Color(163, 21, 21);
	colors[SECTION_COLOR] = entry;

	//attribute color
	entry.normal.text = Color(255, 0, 0);
	colors[ATTRIBUTE_COLOR] = entry;

	//operator color
	entry.normal.text = Color(0, 0, 255);
	colors[OPERATOR_COLOR] = entry;

	//comment color
	entry.normal.text = Color(24, 128, 24);
	colors[COMMENT_COLOR] = entry;

}


IniColorizer::~IniColorizer()
{
}

int IniColorizer::GetStartState()
{
	return 0;
}

int IniColorizer::ColorizeLine(const wchar_t * text, unsigned __int32 * colors, int length, int startState)
{
	if (length > 0)
	{
		if (TEXT(';') == text[0])
		{
			for (int i = 0; i < length; i++)
			{
				colors[i] = COMMENT_COLOR;
			}
		}
		else if (TEXT('[') == text[0])
		{
			for (int i = 0; i < length; i++)
			{
				colors[i] = (text[i] == TEXT('[') || text[i] == TEXT(']')) ? OPERATOR_COLOR : SECTION_COLOR;
			}
		}
		else
		{
			bool afterAssign = false;
			for (int i = 0; i < length; i++)
			{
				if (text[0] == L'=' && !afterAssign)
				{
					afterAssign = true;
					colors[i] = OPERATOR_COLOR;
				}
				else
				{
					colors[i] = afterAssign ? NORMAL_COLOR : ATTRIBUTE_COLOR;
				}
			}
		}
	}
	
	return 0;
}




